# -*- codeing = utf-8 -*-
# @Time : 2021/2/21 18:57
# @Atuthor: 朱朱
# @File: 029循环语句while.py
# @Software: PyCharm

# 求1~100的所有整数之和
i = 0
result = 0  # 定义一个变量用来保存所有数字之和
while i < 100:
    i += 1
    result += i
print(result)


# 求1~100所有偶数的和
i = 0
result = 0  # 定义一个变量用来保存所有数字之和
while i < 100:
    i += 1
    if i % 2 == 0:  # 偶数才被加到result
        result += i
print(result)

# 求 [51,100]之间所有整数的和
y = 0
j = 51
while j < 100:
    j += 1
    y += j
print(y)